//
//  HZUINavAddBottomView.m
//  Constraint
//
//  Created by huazi on 14-5-27.
//  Copyright (c) 2014年 AutoLayoutTestDemo. All rights reserved.
//

#import "HZUINavAddBottomView.h"
#import "UIDevice+Common.h"
#define DeviceRect   [UIScreen mainScreen].bounds
#define DeviceHeight [UIScreen mainScreen].bounds.size.height
#define DeviceWidth [UIScreen mainScreen].bounds.size.width

@implementation HZUINavAddBottomView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        
    }
    return self;
}

- (void)initSubviews
{
    self.backgroundColor =[UIColor clearColor];
    self.viewBJAlpha =[[UIView alloc] initWithFrame:self.frame];
    self.viewBJAlpha.backgroundColor =[UIColor lightGrayColor];
    self.viewBJAlpha.alpha =0.0;
    [self addSubview:self.viewBJAlpha];
    
    
    self.viewCancelAndConfirm =[[UIView alloc] initWithFrame:CGRectMake(0, DeviceHeight-206, DeviceWidth, 44)];
    self.viewCancelAndConfirm.backgroundColor =[UIColor lightGrayColor];
    [self addSubview:self.viewCancelAndConfirm];
    UIButton *btnCancel =[UIButton buttonWithType:UIButtonTypeCustom];
    [btnCancel setTitle:@"取消" forState:UIControlStateNormal];
    [btnCancel setTitleColor: [UIColor colorWithRed:38/255.0 green:138/255.0 blue:195/255.0 alpha:1.0] forState:UIControlStateNormal];
    btnCancel.frame =CGRectMake(10, 7, 50, 30);
    btnCancel.titleLabel.font =[UIFont systemFontOfSize:15.0f];
    [btnCancel addTarget:self action:@selector(BtnToHideSelf:) forControlEvents:UIControlEventTouchUpInside];
    btnCancel.tag =100;
    [self.viewCancelAndConfirm addSubview:btnCancel];
    
    UIButton *btn =[UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitle:@"确定" forState:UIControlStateNormal];
    
    [btn setTitleColor: [UIColor colorWithRed:38/255.0 green:138/255.0 blue:195/255.0 alpha:1.0] forState:UIControlStateNormal];
    btn.frame =CGRectMake(DeviceWidth-60, 7, 50, 30);
    btn.titleLabel.font =[UIFont systemFontOfSize:15.0f];
    [btn addTarget:self action:@selector(BtnToHideSelf:) forControlEvents:UIControlEventTouchUpInside];
    btn.tag =101;
    [self.viewCancelAndConfirm addSubview:btn];
   
    
    if (self.BottomView)
    {
        [self addSubview:self.BottomView];
        self.BottomView.backgroundColor =[UIColor whiteColor];
    }
    
}


- (void)addSubviewToSuperView:(UIView *)superView
{
    [superView addSubview:self];
//    [self addSingleTapToHiddenSelf];
    [UIView animateWithDuration:0.3 animations:^{
        self.viewBJAlpha.alpha =0.5;
    }];
}

- (void)addSingleTapToHiddenSelf
{
    UITapGestureRecognizer *sinletap =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(TapToHideSelf:)];
    sinletap.numberOfTapsRequired =1;
    [self addGestureRecognizer:sinletap];
    
  
}

- (void)BtnToHideSelf:(UIButton *)sender
{
    sender.alpha =0.0f;
    [UIView animateWithDuration:0.3
                     animations:^{
                         self.BottomView.frame =CGRectMake(0,self.frame.size.height +self.BottomView.frame.size.height,DeviceWidth,self.BottomView.frame.size.height);
                         self.viewCancelAndConfirm.frame =CGRectMake(0, self.frame.size.height +self.viewCancelAndConfirm.frame.size.height ,DeviceWidth, self.viewCancelAndConfirm.frame.size.height);
                         self.viewBJAlpha.alpha =0.0f;
                         
                         
                     }
                     completion:^(BOOL finish)
     {
         [self removeFromSuperview];
     }];

    if (sender.tag ==101)
    {
        if ([self.delegate respondsToSelector:@selector(getStrFromBottomView:)])
        {
            [self.delegate getStrFromBottomView:self];
        }
    }

}
- (void)TapToHideSelf:(id)sender
{
    [UIView animateWithDuration:0.3
                     animations:^{
                         self.BottomView.frame =CGRectMake(0,self.frame.size.height +self.BottomView.frame.size.height,320,self.BottomView.frame.size.height);
                         self.viewBJAlpha.alpha =0.0f;
                         [self viewWithTag:100].alpha =0.0f;
                         
                     }
                     completion:^(BOOL finish)
    {
        [self removeFromSuperview];
    }];
}

@end
